/**
 * 
 */
package test.net;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.Date;

import org.apache.commons.net.ftp.FTPFile;
import org.junit.Test;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonAnyFormatVisitor;

import hyl.base.net.ftp.Ftp;
import hyl.core.MyCharset;
import hyl.core.MyFun;
import hyl.core.SysInfo;
import hyl.core.io.MyFile;
import hyl.core.io.MyPath;

/**
 * @author 邹达有
 * @mail 37798955@qq.com
 * 
 *       2022年7月29日
 * 
 */
public class testftp {
	// @Test
	public void testftp批量上传() throws FileNotFoundException {

		Ftp ftp = new Ftp("192.168.0.143", 921, "zdy", "123456",MyCharset._GBK,MyCharset._UTF8);
		String[] listString = MyFile.get子文件路径列表("D:\\Temp\\downimg");
		// System.out.println(listString);
		ftp.do登录();

		for (String s : listString) {
			System.out.println("上传" + s);
			File f = new File(s);
			System.out.println(f.lastModified());
//			InputStream is = new FileInputStream(new File(s));
//			ftp.do上传("/upload/1", f.getName(), is);
		}

		for (FTPFile s : ftp.get文件列表("/upload/1")) {
			System.out.println(JSON.toJSONString(s));
			System.out.println(Date.from(s.getTimestamp().toInstant()));
		}

		// ftp.do下载("/root/nginx/uploadFile/","001.txt", "D:\\downfile\\test.txt");
		ftp.do断开连接();
		System.out.println("完成上传");
	}

//	@Test
	public void testftp批量下载() throws FileNotFoundException {

		Ftp ftp = new Ftp("192.168.0.143", 921, "zdy", "123456",MyCharset._GBK,MyCharset._UTF8);

		// System.out.println(listString);
		ftp.do登录();
		
		for (FTPFile s : ftp.get文件列表("/upload/1")) {
			System.out.println(JSON.toJSONString(s));
			System.out.println(Date.from(s.getTimestamp().toInstant()));
			if (s.isFile())
				ftp.do下载("/upload/1",s.getName(), "D:\\downfile\\"+s.getName());
			else if (s.isDirectory())
				MyFile.openDir("D:\\downfile\\"+s.getName());
				
		}
		System.out.println("完成下载");
		String[] listString = MyFile.get子文件路径列表("D:\\downfile\\");

		for (String s : listString) {
			System.out.println("下载" + s);
			File f = new File(s);
			System.out.println(f.lastModified());
		}

		ftp.do断开连接();
	
	}
	
	public void testftp下载目录() throws FileNotFoundException {

		Ftp ftp = new Ftp("192.168.0.143", 921, "zdy", "123456",MyCharset._GBK,MyCharset._UTF8);

		// System.out.println(listString);
		ftp.do登录();
		ftp.do下载目录("/upload/1", "D:\\downfile/2");
		System.out.println("完成下载");
		//System.out.println(System.getProperties().getProperty("os.name")); 		
	
		ftp.do断开连接();
		MyCharset.show() ;
	
	}

	@Test
	public void testftp上传目录() throws FileNotFoundException {

		Ftp ftp = new Ftp("192.168.0.143", 921, "zdy", "123456",MyCharset._GBK,MyCharset._UTF8);
		// System.out.println(pp.getRoot());
		// System.out.println(listString);
		ftp.do登录();
		//ftp.do创建目录("/upload/2/cc/tt");
		//ftp.创建目录("pp/oo");
		ftp.do上传目录("/upload/1", "D:\\downfile/1");
		System.out.println("上传完成");
		ftp.do断开连接();

	}
}
